package com.wkbb.basic.controller.manage;

import com.github.pagehelper.PageInfo;
import com.wkbb.common.dto.basic.ClassInfo;
import com.wkbb.basic.model.TeacherCourse;
import com.wkbb.basic.service.ClassInfoService;
import com.wkbb.basic.utils.RandomUtil;
import com.wkbb.basic.vo.ClassManageEditVo;
import com.wkbb.basic.vo.TeacherCourseVo;
import com.wkbb.common.base.BaseController;
import com.wkbb.common.constants.ErrorCode;
import com.wkbb.common.constants.VersionConstant;
import com.wkbb.common.dto.ResultDTO;
import com.wkbb.common.dto.basic.UserDto;
import com.wkbb.common.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Lilin
 */
@RestController
@Api(description = "班级管理(后台管理)")
@RequestMapping("/basic/{apiVersion}/classinfo/manage")
@Slf4j
public class ClassInfoManageController extends BaseController {

    @Autowired
    private ClassInfoService classInfoService;

    @ApiOperation(value = "批量加入班级(非常规班)")
    @RequestMapping(value = "/joinClassByStudents", method = RequestMethod.POST)
    public ResultDTO<Boolean> joinClassByStudents(
            @ApiParam(value = "接口版本", defaultValue = VersionConstant.V1, required = true) @PathVariable(name = "apiVersion") String apiVersion,
            @ApiParam(value = "学生id(多个,号隔开)", required = true) @RequestParam(name = "studentIds", required = true) String studentIds,
            @ApiParam(value = "班级id", required = true) @RequestParam(name = "classId", required = true) Long classId
    ) {
        log.info("***********ClassInfoManageController.joinClassByStudents******...studentIds:{}，classId:{}", studentIds, classId);
        if (StringUtil.isEmpty(studentIds)) {
            return new ResultDTO<>(ErrorCode.PARAM_MISSING);
        }
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }
        try {
            return classInfoService.joinClassByStudents(studentIds,classId,1);
        } catch (Exception e) {
            log.error("***********ClassInfoManageController.joinClassByStudents******", e);
            return new ResultDTO<>(false);
        }
    }

    @ApiOperation(value = "批量退出班级(非常规班)")
    @RequestMapping(value = "/exitClassByStudents", method = RequestMethod.POST)
    public ResultDTO exitClassByStudents(
            @ApiParam(value = "接口版本", defaultValue = VersionConstant.V1, required = true) @PathVariable(name = "apiVersion") String apiVersion,
            @ApiParam(value = "学生id(多个,号隔开)", required = true) @RequestParam(name = "studentIds", required = true) String studentIds,
            @ApiParam(value = "班级id", required = true) @RequestParam(name = "classId", required = true) Long classId
    ) {
        log.info("***********ClassInfoManageController.joinClassByStudents******...studentIds:{}，classId:{}", studentIds, classId);
        if (StringUtil.isEmpty(studentIds)) {
            return new ResultDTO<>(ErrorCode.PARAM_MISSING);
        }
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }
        try {
            return classInfoService.joinClassByStudents(studentIds,classId,2);
        } catch (Exception e) {
            log.error("***********ClassInfoManageController.joinClassByStudents******", e);
            return new ResultDTO<>(false);
        }
    }

    @ApiOperation(value = "新增班级")
    @RequestMapping(method = RequestMethod.POST)
    public ResultDTO<Long> add(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "班级详情", required = true) @RequestBody ClassManageEditVo classManageDto) {

        log.info("***********ClassInfoManageController.add******apiVersion:{},classManageDto:{}", apiVersion, classManageDto);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        ClassInfo classInfo = classManageDto.getClassInfo();
        List<TeacherCourseVo> teacherCourseList = classManageDto.getTeacherCourseList();

        try {
            if (checkData(classInfo)) {
                return new ResultDTO<>(ErrorCode.PARAM_MISSING);
            }

            Map<String, Object> params = new HashMap<String, Object>();
            params.put("orgId", classInfo.getOrgId());
            params.put("gradeId", classInfo.getGradeId());
            params.put("className", classInfo.getClassName());
            ClassInfo oldClassInfo = classInfoService.getByMapParams(params);
            if(null!=oldClassInfo){
                return new ResultDTO<>(ErrorCode.CLASS_NOT_REPEAT);
            }

            //检查是否已是班主任
          /*  if (classInfo.getMasterId() != null && classInfo.getMasterId() != 0) {
                //查询是否在该学校有任班主任
                Long orgId = classManageDto.getClassInfo().getOrgId().longValue();
                ClassInfoDto classInfoByMasterId = classInfoService.getClassInfoByMasterId(orgId,classInfo.getMasterId());
                // 同一个人在相同机构只能当任一个班的班主任
                if (classInfoByMasterId != null) {
                    return new ResultDTO<>(ErrorCode.IS_MASTER_ALREADY);
                }
            }*/
             
            classInfo.setCreateBy(userDto.getName());
            classInfo.setUpdateBy(userDto.getName());
            classInfo.setStatus(true);
            classInfo.setInviteCode(RandomUtil.generateString(8));
//            classInfo.setStatus(true);
            classInfoService.addClass(classInfo, teacherCourseList);
            return new ResultDTO<>(classInfo.getId());
        } catch (Exception e) {
            log.error("***********ClassInfoManageController.add******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    /**
     * 检查是否班级信息
     *
     * @param classInfo 班级信息
     * @return 是否未通过检查
     */
    private boolean checkData(ClassInfo classInfo) {
        return classInfo == null || classInfo.getOrgId() == null || classInfo.getOrgId() == 0
               // || StringUtil.isNullOrBlank(classInfo.getGradeName())
                || StringUtil.isNullOrBlank(classInfo.getClassName())
                || classInfo.getGradeId() == null || classInfo.getGradeId() == 0;
                //|| classInfo.getDateBegin() == null || classInfo.getDateEnd() == null
//                || classInfo.getMasterId() == null || classInfo.getMasterId() == 0;
               // || StringUtil.isNullOrBlank(classInfo.getMasterPhone());
    }

    @ApiOperation(value = "更新班级")
    @RequestMapping(method = RequestMethod.PUT)
    public ResultDTO<Long> update(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "班级详情", required = true) @RequestBody ClassManageEditVo classManageDto) {

        log.info("***********ClassInfoManageController.update******apiVersion:{},classManageDto:{}", apiVersion, classManageDto);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        ClassInfo classInfo = classManageDto.getClassInfo();
        //List<TeacherCourseVo> teacherCourseList = classManageDto.getTeacherCourseList();

        try {
            if (checkData(classInfo) || classInfo.getId() == null || classInfo.getId() == 0) {
                return new ResultDTO<>(ErrorCode.PARAM_MISSING);
            }

            Map<String, Object> params = new HashMap<String, Object>();
            params.put("orgId", classInfo.getOrgId());
            params.put("gradeId", classInfo.getGradeId());
            params.put("className", classInfo.getClassName());
            ClassInfo oldClassInfo = classInfoService.getByMapParams(params);
            if(null!=oldClassInfo&&oldClassInfo.getId().intValue()!=classInfo.getId().intValue()){
                return new ResultDTO<>(ErrorCode.CLASS_NOT_REPEAT);
            }

            //检查是否已是班主任
           /* if (classInfo.getMasterId() != null && classInfo.getMasterId() != 0) {
                Long orgId = classManageDto.getClassInfo().getOrgId().longValue();
                ClassInfoDto classInfoByMasterId = classInfoService.getClassInfoByMasterId(orgId,classInfo.getMasterId());
                // 同一个人在相同机构只能当任一个班的班主任
                if (classInfoByMasterId != null&& classInfoByMasterId.getId() != classInfo.getId().longValue()) {
                    return new ResultDTO<>(ErrorCode.IS_MASTER_ALREADY);
                }
            }*/

            classInfo.setUpdateBy(userDto.getName());

//            if(CollectionUtils.isNotEmpty(teacherCourseList)){
//
//                for(TeacherCourseVo teacherCourseVo:teacherCourseList){
//                    teacherCourseVo.setClassId(classInfo.getId());
//                }
//            }
           // classInfoService.update(classInfo, null, true);
            classInfoService.update(classInfo, true);
            return new ResultDTO<>(classInfo.getId());
        } catch (Exception e) {
            log.error("***********ClassInfoManageController.update******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "删除班级")
    @RequestMapping(method = RequestMethod.DELETE)
    public ResultDTO delete(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "班级ID", required = true) @RequestParam(name = "id", required = true) List<Long> ids) {
        log.info("***********ClassInfoManageController.delete******ids:{}", ids);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }
        try {
            return classInfoService.delete(ids, userDto.getName());
        } catch (Exception e) {
            log.error("***********ClassInfoManageController.delete******", e);
            return new ResultDTO(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询班级详情")
    @RequestMapping(value = "info", method = RequestMethod.GET)
    public ResultDTO<ClassManageEditVo> info(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "班级ID", required = true) @RequestParam(name = "id", required = true) Long id) {

        log.info("***********ClassInfoManageController.info******apiVersion:{},id:{}", apiVersion, id);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            return new ResultDTO<>(classInfoService.getClassInfoWithCoursesById(id));
        } catch (Exception e) {
            log.error("***********ClassInfoManageController.info******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询学校统计班级数量、年级数量")
    @RequestMapping(value = "getClassAndGradeCount", method = RequestMethod.GET)
    public ResultDTO<Map<String, Object>> getClassAndGradeCount(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "是否为常规班") @RequestParam(name = "isRoutine", required = false) Boolean isRoutine,
            @ApiParam(value = "学校ID", required = true) @RequestParam(name = "orgId", required = true) Long orgId) {
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }
        try {
            if (orgId == 0) {
                return new ResultDTO<>(ErrorCode.PARAM_MISSING);
            }

            Map<String, Object> params = new HashMap<>();
            if (orgId != 1) params.put("orgId", orgId);
            params.put("status", 1);
            params.put("isRoutine", isRoutine);
            return new ResultDTO<>(classInfoService.getClassAndGradeCount(params));
        } catch (Exception e) {
            log.error("***********ClassInfoManageController.page******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询班级分页列表")
    @RequestMapping(value = "page", method = RequestMethod.GET)
    public ResultDTO<PageInfo<ClassInfo>> page(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "学校ID", required = true) @RequestParam(name = "orgId", required = true) Long orgId,
            @ApiParam(value = "年级ID", required = false) @RequestParam(name = "gradeId", required = false) Long gradeId,
            @ApiParam(value = "班级名称（模糊搜索）", required = false) @RequestParam(name = "className", required = false) String className,
            @ApiParam(value = "班主任姓名（模糊搜索）", required = false) @RequestParam(name = "masterName", required = false) String masterName,
            @ApiParam(value = "入学年份", required = false) @RequestParam(name = "enrollmentYear", required = false) Integer enrollmentYear,
            @ApiParam(value = "是否为常规班") @RequestParam(name = "isRoutine", required = false) Boolean isRoutine,
            @ApiParam(value = "班级类型", required = false, defaultValue = "1") @RequestParam(name = "classType", required = false) Integer classType,
            @ApiParam(value = "页码", required = true, defaultValue = "1") @RequestParam(name = "pageNo", required = true, defaultValue = "1") Integer pageNo,
            @ApiParam(value = "每页条数", required = true, defaultValue = "10") @RequestParam(name = "pageSize", required = true, defaultValue = "10") Integer pageSize) {
        log.info("***********ClassInfoManageController.page******apiVersion:{},orgId:{},gradeId:{},className:{},masterName:{},pageNo:{},pageSize:{}",
                apiVersion, orgId, gradeId, className, masterName, pageNo, pageSize);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            if (orgId == 0) {
                return new ResultDTO<>(ErrorCode.PARAM_MISSING);
            }

            Map<String, Object> params = new HashMap<>();
            params.put("orgId", orgId);
            params.put("gradeId", gradeId);
            params.put("enrollmentYear", enrollmentYear);
            params.put("classType", classType);
            params.put("isRoutine", isRoutine);
            if (!StringUtil.isNullOrBlank(className)) {
                params.put("className", className);
            }
            if (!StringUtil.isNullOrBlank(masterName)) {
                params.put("masterName", masterName);
            }
            params.put("status", 1);
            return new ResultDTO<>(classInfoService.getListByPage(params, pageNo, pageSize));
        } catch (Exception e) {
            log.error("***********ClassInfoManageController.page******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询全校班级列表(不分页)")
    @RequestMapping(value = "list", method = RequestMethod.GET)
    public ResultDTO<List<ClassInfo>> list(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "学校ID", required = true) @RequestParam(name = "orgId", required = true) Long orgId,
            @ApiParam(value = "是否为常规班") @RequestParam(name = "isRoutine", required = false) Boolean isRoutine) {
        log.info("***********ClassInfoManageController.list******apiVersion:{},orgId:{},gradeId:{},className:{},masterName:{}",
                apiVersion, orgId);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            if (orgId == 0) {
                return new ResultDTO<>(ErrorCode.PARAM_MISSING);
            }

            Map<String, Object> params = new HashMap<>(2);
            params.put("orgId", orgId);
            params.put("status", 1);
            params.put("isRoutine", isRoutine);
            return new ResultDTO<>(classInfoService.getListByMapParams(params));
        } catch (Exception e) {
            log.error("***********ClassInfoManageController.list******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "新增任课教师")
    @RequestMapping(value = "teacherCourse", method = RequestMethod.POST)
    public ResultDTO addTeacherCourse(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "负责人ID", required = true, defaultValue = "111") @RequestParam(name = "masterId", required = true) List<Long> masterId,
            @ApiParam(value = "班级ID", required = true, defaultValue = "3") @RequestParam(name = "classId", required = true) Long classId,
            @ApiParam(value = "课程名称", required = true, defaultValue = "Python") @RequestParam(name = "courseName", required = true) String courseName) {
        log.info("***********ClassInfoManageController.addTeacherCourse******apiVersion:{},masterId:{},classId:{}，courseName:{}",
                apiVersion, masterId, classId, courseName);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            if (CollectionUtils.isEmpty(masterId)) {
                return new ResultDTO(ErrorCode.PARAM_MISSING);
            }

            ClassInfo classInfo = classInfoService.getByPrimaryKey(classId);
            if (classInfo == null) {
                return new ResultDTO(ErrorCode.CLASS_NOT_EXISTS);
            }

            classInfoService.addTeacherCourse(masterId, classInfo, courseName);
            return new ResultDTO();
        } catch (Exception e) {
            log.error("***********ClassInfoManageController.addTeacherCourse******", e);
            return new ResultDTO(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "删除任课教师")
    @RequestMapping(value = "teacherCourse", method = RequestMethod.DELETE)
    public ResultDTO deleteTeacherCourse(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "课程ID", required = true, defaultValue = "3") @RequestParam(name = "courseId", required = true) Long courseId) {
        log.info("***********ClassInfoManageController.deleteTeacherCourse******apiVersion:{},courseId:{}", apiVersion, courseId);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            if (courseId == 0) {
                return new ResultDTO(ErrorCode.PARAM_MISSING);
            }

            classInfoService.deleteTeacherCourse(courseId);
            return new ResultDTO();
        } catch (Exception e) {
            log.error("***********ClassInfoManageController.deleteTeacherCourse******", e);
            return new ResultDTO(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "获取任课教师列表")
    @RequestMapping(value = "teacherCourse", method = RequestMethod.GET)
    public ResultDTO<List<TeacherCourse>> getTeacherCourse(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "班级ID", required = true, defaultValue = "3") @RequestParam(name = "classId", required = true) Long classId) {
        log.info("***********ClassInfoManageController.deleteTeacherCourse******apiVersion:{},classId:{}", apiVersion, classId);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            if (classId == 0) {
                return new ResultDTO<>(ErrorCode.PARAM_MISSING);
            }

            Map<String, Object> params = new HashMap<>(1);
            params.put("classId", classId);
            params.put("status", 1);

            return new ResultDTO<>(classInfoService.getTeacherCourse(params));
        } catch (Exception e) {
            log.error("***********ClassInfoManageController.deleteTeacherCourse******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    //1.先循环学校
    //2.再循环学校下的班级
    //3.给每个班级设置班主任
    //4.IM自动建群

    /**
     * 临时方案,以后会废弃掉
     *
     * @param apiVersion
     * @return
     */
    @ApiOperation(value = "程序自动创建群")
    @RequestMapping(value = "autoCreateChatGroup", method = RequestMethod.POST)
    public ResultDTO autoCreateChatGroup(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "学校ID", required = false, defaultValue = "1") @RequestParam(name = "orgId", required = false) Long orgId) {
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }
        try {
            return new ResultDTO(classInfoService.autoCreateChatGroup(orgId));
        } catch (Exception e) {
            log.error("***********ClassInfoManageController.autoCreateChatGroup******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    /**
     * 升班
     *
     * @param apiVersion
     * @return
     */
    @ApiOperation(value = "升班")
    @RequestMapping(value = "upClass", method = RequestMethod.POST)
    public ResultDTO upClass(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "学校ID", required = true) @RequestParam(name = "orgId", required = true) Long orgId,
            @ApiParam(value = "年级ID", required = true) @RequestParam(name = "newGradeId", required = true) Long newGradeId,
            @ApiParam(value = "班级ID", required = true) @RequestParam(name = "classId", required = true) Long classId,
            @ApiParam(value = "班级名称", required = false) @RequestParam(name = "className", required = false) String className,
            @ApiParam(value = "班主任ID", required = false) @RequestParam(name = "masterId", required = false) Long masterId) {

        log.info("*******upClass orgId:{} newGradeId:{} classId:{} className:{} masterId:{}******",orgId,newGradeId,classId,className,masterId);

        try
        {
            UserDto userDto = getUserByLogin();
            if (userDto == null) {
                return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
            }

            //判断是否班级重名
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("orgId", orgId);
            params.put("gradeId", newGradeId);
            params.put("className", className);
            ClassInfo oldClassInfo = classInfoService.getByMapParams(params);
            if(null!=oldClassInfo&&oldClassInfo.getId().intValue()!=classId.intValue()){
                return new ResultDTO<>(ErrorCode.CLASS_NOT_REPEAT);
            }

            classInfoService.upClass(orgId,newGradeId,classId,className,masterId,userDto.getName());
            return new ResultDTO<>(true);
        } catch (Exception e) {
            log.error("***********ClassInfoManageController.autoCreateChatGroup******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }
        
        @ApiOperation(value = "升年级和班")
        @RequestMapping(value = "upGradeClass", method = RequestMethod.POST)
        public ResultDTO upGradeClass(
                @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
                @ApiParam(value = "学校ID", required = true) @RequestParam(name = "orgId", required = true) Long orgId,
                @ApiParam(value = "年级ID", required = false) @RequestParam(name = "gradeId", required = false) Long gradeId,
                @ApiParam(value = "班级ID", required = false) @RequestParam(name = "classId", required = false) Long classId
               ) {


            try
            {
                UserDto userDto = getUserByLogin();
                if (userDto == null) {
                    return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
                }

               

                classInfoService.upGradeClass(orgId,gradeId,classId,userDto.getName());
                return new ResultDTO<>(true);
            } catch (Exception e) {
                log.error("***********ClassInfoManageController.autoCreateChatGroup******", e);
                return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
            }

    }

}
